package com.example.moments.repository;

import android.annotation.SuppressLint;
import android.os.AsyncTask;

import androidx.room.Query;

import com.example.moments.dao.BaseDao;
import com.example.moments.dao.CommentDao;
import com.example.moments.ssmemo.entity.Comment;
import com.example.moments.ssmemo.entity.Content;

import java.util.List;
import java.util.concurrent.ExecutionException;

//import en.edu.zucc.pb.loginapplication.AppDatabase;
//import en.edu.zucc.pb.loginapplication.dao.UserDao;
//import en.edu.zucc.pb.loginapplication.entity.User;

//import androidx.lifecycle.LiveData;
//import cn.chenjianlink.android.alarmclock.db.AlarmClockDao;
//import cn.chenjianlink.android.alarmclock.db.BaseAlarmClockDatabase;
//import cn.chenjianlink.android.alarmclock.model.AlarmClock;
//import cn.chenjianlink.android.alarmclock.utils.LogUtil;

/**
 * @author chenjian
 * 对数据库操作进行封装，向ViewModel提供封装方法
 */
public class CommentRepository extends BaseRepository<Comment> {

//    private static ContentDao contentDao;

    public static void main(String[] args) {
//        AppDatabase database = AppDatabase.getDatabase(getApplicationContext());
//        ContentDao contentDao = database.contentDao();
//        ContentRepository contentRepository=new ContentRepository(contentDao);
//        contentRepository.update(new Content());
    }
//    private final ContentDao contentDao;

//    private final LiveData<List<User>> userList;

    /**
     * 线程池，在子线程中处理增删改
     */
//    private final ExecutorService executor;

    public CommentRepository(BaseDao<Comment> baseDao) {
        super(baseDao);
    }

//    @Query("SELECT * FROM " + Comment.TABLE_NAME+ " where contentId = :contentId " )
   public List<Comment> getAllByContentId(Long contentId) throws ExecutionException, InterruptedException {
        return new AsyncTask<Long , Void, List<Comment> >() {
            //            @SuppressLint("StaticFieldLeak")
//            @SuppressLint("StaticFieldLeak")
            @Override
            protected List<Comment> doInBackground(Long ... ids) {
                CommentDao commentDao= (CommentDao) getBaseDao();
              return   commentDao.getAllByContentId(ids[0]);
//                return   getBaseDao().getAll(ids);
            }

        }.execute(contentId ).get();
    }
//每次一个查询 都要写 dao 还要写 repository
}
